package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.Settings;
import com.tanhua.dubbo.api.SettingsApi;
import com.tanhua.dubbo.mapper.SettingsMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service(timeout = 200000)
public class SettingsApiImpl implements SettingsApi {
    @Autowired
    private SettingsMapper settingsMapper;

    @Override
    public Settings findByUserId(Long userId) {
        // SELECT * FROM tb_settings WHERE user_id=1
        // 创建查询条件对象
        QueryWrapper<Settings> wrapper = new QueryWrapper<>();
        // 添加查询条件，相当于 WHERE user_id=1
        wrapper.eq("user_id",userId);
        // 通过mybatis-plus提供的通用方法，实现条件查询
        Settings settings = settingsMapper.selectOne(wrapper);
        return settings;
    }

    @Override
    public void save(Settings settings) {
        settingsMapper.insert(settings);
    }

    @Override
    public void update(Settings settings) {
        settingsMapper.updateById(settings);
    }
}
